//
//  LQLaunchControler.m
//  LQWeChat
//
//  Created by liquan on 2017/11/27.
//  Copyright © 2017年 liquan. All rights reserved.
//

#import "LQLaunchControler.h"
#import "LQMainViewController.h"
#import "LQFirstViewController.h"


@interface LQLaunchControler()
@property(nonatomic,strong)UIViewController *rootViewController;
@property(nonatomic)LQMainViewController *mainViewController;
@property(nonatomic)LQFirstViewController *firstViewController;
@end


@implementation LQLaunchControler


LQKSingletonM


-(void)launchInWindow:(UIWindow *)window{
    [[NSUserDefaults standardUserDefaults]setBool:NO forKey:LQISNotFristLunch];
    if ([self lqk_isNotFirstLaunch]) {
        
         window.rootViewController = self.mainViewController;
         self.rootViewController = self.mainViewController;
    }else{
       
        window.rootViewController = self.firstViewController;
        self.rootViewController = self.firstViewController;
        WeakSelf(weakSelf);
        [self.firstViewController setFinishFirstLaunchBlock:^{
            window.rootViewController = weakSelf.mainViewController;
            [weakSelf lqk_setupIsNotLaunchFirst];
        }];
    }
}


-(LQFirstViewController *)firstViewController{
    if (!_firstViewController) {
        _firstViewController = [[LQFirstViewController alloc]init];
    }
    return _firstViewController;
}


-(LQMainViewController *)mainViewController{
    if (!_mainViewController) {
        _mainViewController = [[LQMainViewController alloc]init];
    }
    return _mainViewController;
}


-(BOOL)lqk_isNotFirstLaunch{
    return  [[NSUserDefaults standardUserDefaults]boolForKey:LQISNotFristLunch];
}


-(void)lqk_setupIsNotLaunchFirst{
    [[NSUserDefaults standardUserDefaults]setBool:YES forKey:LQISNotFristLunch];
}

@end
